package com.byx.imserverutil.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * ServerIdleStateTrigger
 *
 * @author Superb
 * @date 2021/4/4 16:14
 */
public class ServerIdleStateTrigger extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent){
            IdleState state = ((IdleStateEvent) evt).state();
            if (state == IdleState.READER_IDLE){
                ctx.disconnect();
            }else if (state == IdleState.WRITER_IDLE){

            }else if (state == IdleState.ALL_IDLE){

            }
        }else {
            super.userEventTriggered(ctx, evt);
        }
    }
}
